
var gulp = require('gulp'),

    minifycss = require('gulp-minify-css'),

    concat = require('gulp-concat'),

    uglify = require('gulp-uglify'),

    rename = require('gulp-rename'),

    del = require('del');

var stream = require('stream');

var File = require("vinyl")

var buildjs = require("./buildjs")

var babel = require("gulp-babel");

var config = require("./config");

let outDir = "dist/js/";

gulp.task('minifycss', function() {

    return gulp.src('src/*.css')      //压缩的文件

        .pipe(gulp.dest('dist/css'))   //输出文件夹

        .pipe(minifycss());   //执行压缩

});



gulp.task("babel", function () {
  return gulp.src("src/*/*.js")
    .pipe(babel())
    .pipe(gulp.dest("temp"));
});

gulp.task('clean',async() => {
   await del(['dist/css', 'dist/js','temp'])
})

gulp.task('buildjs', function(cb) {
	
	buildjs.mkdir(outDir);
	for (var i = 0; i < config.list.length; i++) {
		let cfg = config.list[i];
		buildjs.parse("temp/"+cfg.dir,outDir,cfg.name);
	}
	buildjs.outIndex(outDir);
    cb();
});

gulp.task('minifyjs', function() {

    return gulp.src(outDir+"*js")

        .pipe(rename({suffix: '.min'}))   //rename压缩后的文件名

        .pipe(uglify())    //压缩

        .pipe(gulp.dest('dist/js'));  //输出

});

gulp.task('default',gulp.series('clean','babel','buildjs','minifyjs', (done) => {
    console.log(" gulp finish ")
    done();
}));